﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Commerce.Data;

namespace Commerce.CSK.Web.Controls
{
    public partial class CategoryMain : ItemViewControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private Category _selectedCategory;
        public Category SelectedCategory
        {
            get
            {
                if (_selectedCategory == null)
                {
                    int? categoryId = ItemId;
                    if (categoryId != null && categoryId.HasValue)
                    {
                        _selectedCategory = Services.GetCatalogService().GetCategory(categoryId.Value); 
                    }
                }
                return _selectedCategory; 
            }

            set
            {
                _selectedCategory = value;
                if (value != null)
                {
                    ItemId = value.ID;
                    catalogProductList.DataSource = _selectedCategory.Products;
                }
                else
                {
                    ItemId = null; 
                }
            }
        }
    }
}